'use strict';
const dayjs = require("dayjs");

module.exports = app => {
    const { INTEGER, STRING, DATE } = app.Sequelize;
    const Enterprise = app.model.define(
        'Enterprise',
        {
            id: { type: INTEGER, primaryKey: true, autoIncrement: true },
            type: { type: STRING(20), allowNull: false, comment: '企业类型' },
            text: { type: STRING(100), allowNull: false, comment: '企业名称' },
            enterprise_type: { type: STRING(20), allowNull: true, comment: '企业分类（瞪羚/独角兽）' },
            create_time: {
                type: DATE,
                get() {
                    return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            update_time: {
                type: DATE,
                get() {
                    return dayjs(this.getDataValue('update_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            }
        },
        {
            tableName: 'enterprise',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    return Enterprise;
};

// MySQL建表语句
// CREATE TABLE `enterprise` (
//   `id` int(11) NOT NULL AUTO_INCREMENT,
//   `type` varchar(20) NOT NULL COMMENT '企业类型',
//   `text` varchar(100) NOT NULL COMMENT '企业名称',
//   `enterprise_type` varchar(20) DEFAULT NULL COMMENT '企业分类（瞪羚/独角兽）',
//   `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
//   `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
//   PRIMARY KEY (`id`),
//   UNIQUE KEY `idx_text` (`text`) COMMENT '企业名称唯一索引'
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='企业表';
